<?php
  function act_form_validation($form) {
  
	//print_r($form); die;
	
    $stat = new set_static_variable();
	//print_r($form['field_act_dpt']); die;
	
	//check the corresponding concerned dept name
	
	//chk_concerned_dept($form['field_act_dpt']);
    //Duplication in title

  // check_title_duplication($form['title'], $form['type']['#value'], $form['field_act_dpt'], 'field_act_dpt', $stat->get_nid());
  
   	$stat->set_nid(0);
 
    
	/*District Validation*/
   distvalidation($form['field_act_concerned_district']['und']['#value']);
   //print_r($dist_value); 
   
   //if(array_key_exists('0', $dist_value) && count($dist_value)==1){
   		//echo "if you choose all you cannot choose other district";
  // }
   
    //if(count($dist_value)>1 && $dist_value['0']=='0'){
	
			//echo "you cannot choose all";
	//}
	
	
    /*if ($dist_value['0'] != '' || $dist_value == ' ') {
      form_set_error('field_act_concerned_district', t('%field_title field is required.', 
     array('%field_title' => $form['field_act_concerned_district']['#title'])));  
    }*/
	
	
	// District
	/*if(sizeof($form['field_act_concerned_district']['und']['value']['#value'])>1 && $form['field_act_concerned_district']['und']['value']['#value'][0]==0){
    
    $field=$form['field_act_concerned_district']['und']['value']['#value'][0];
    $field_title=$form['field_act_concerned_district']['#title'];
     
    form_set_error($field, $field_title . ' field can have either \'ALL\' or \'Other Districts\'');
    }*/
	
	// maximum length validation for Title and Description Field
    maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');
	
	// Act Number 
	check_integer($form['field_act_number']['und'][0]['value']['#value'],$form['field_act_number']['und'][0]['value']['#title'],'field_act_number');
	
	// Act Year 
	check_integer($form['field_act_year']['und'][0]['value']['#value'],$form['field_act_year']['und'][0]['value']['#title'],'field_act_year');
	years($form['field_act_year']['und'][0]['value']['#value'],$form['field_act_year']['und'][0]['value']['#title'],'field_act_year');
	
	//print_r($form['field_act_comm_date']['und'][0]['value']['date']['#value']);
	
	//minimum length charcter   
  	minilength_validation($form['field_act_title']['und'][0]['value']['#value'], 5, $form['field_act_title']['und'][0]['value']['#title'], 'field_act_title');
  	minilength_validation($form['field_act_keyword']['und'][0]['value']['#value'], 5, $form['field_act_keyword']['und'][0]['value']['#title'],'field_act_keyword');
	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
    //minilength_validation($form['field_act_objectives']['und'][0]['value']['#value'], 5, $form['field_act_objectives']['und'][0]['value']['#title'], 'field_act_objectives');

//print_r($form['field_act_title']['und'][0]['value']);
//echo $form['field_act_title']['und'][0]['value']['#value'];
//echo "1213".$form['field_act_url']['und'][0]['value'] ['#value'];
//chkbadchar($form['field_act_title']['und'][0]['value']['#value']);

//echo $form['field_act_url']['und'][0]['value']['#value'];
//echo $form['field_act_url']['und'][0]['value']['#value'];

 // Check bad character validation
    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title'); 
	chkbadchar($form['field_act_title']['und'][0]['value']['#value'],$form['field_act_title']['und'][0]['value']['#title']);
    //chkbadchar($form['field_act_extent']['und'][0]['value']['#value'], $form['field_act_extent']['und'][0]['value']['#title'], 'field_act_extent');
    chkbadchar($form['field_act_objectives']['und'][0]['value']['#value'], $form['field_act_objectives']['#title'], 'field_act_objectives');   
    chkbadchar($form['field_act_keyword']['und'][0]['value'] ['#value'], $form['field_act_keyword']['und'][0]['value'] ['#title'], 'field_act_keyword'); 
    
	// Act Number and Act year validaiton 
    check_char_integer($form['field_act_number'][0]['value']['#value'], $form['field_act_number']['#title'],$form['field_act_number'][0]['#field_name']);    
  
    check_integer($form['field_act_year'][0]['value']['#value'], $form['field_act_year']['#title'], $form['field_act_year'][0]['#field_name']);
   
    // Date Validation
 	//check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
	
	// Commencement date
	Commencement_date($form['field_act_comm_date']['und'][0]['value']['date']['#value'],$form['field_act_comm_date']['und'][0]['#title'],'field_act_comm_date');
   
   //Availability act details validation

	url_validation($form['field_act_url']['und'][0]['value']['#value']);
	//print_r($form_type);
	
	//if ($form['field_act_details']['und']['#value'] == 'online') {  
    //$reference_url = $form['field_act_url'][0]['value']['#value'];
	//$reference_url = url_validation($reference_url);
	
	//$reference_url=$form['field_act_url']['und'][0]['value']['#value'];
	
    //if ($form['field_act_details']['und']['#value'] == 'online') {  
      //form_set_error('field_act_url', t('Not a valid URL given in %name field', array(
                                                  // '%name' => $form['field_act_url']['und'][0]['value']['#value']['#title'])));    
    //}
	
    //elseif ($reference_url == '') {
    //  form_set_error('field_act_url', t(' %name field is required', array(
                                                  // '%name' => $form['field_act_url']['und'][0]['value']['#value']['#title'])));
   //}
  
	if ($form['field_act_details']['und']['#value'] == 'download') { 
    // Validating the file size   
    //$field_obj = $form['field_act_file_upload']; 
	//$file_allowed_obj = $form_type;
	//print_r($form['field_act_file_upload']);
	$filename = $form['field_act_file_upload']['und'][0]['#file']; 
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_act_details']['und']['#title']);  
  
  }
  }
  
    function act_presave_validaiton($node) {
    $reference_url = $node->field_act_url['und'][0]['value'];
    $node->field_act_url['und'][0]['value'] = url_validation($reference_url);
  } // function act_presave_validaiton()
   
    
